from pathlib import Path

###本项目的根目录路径
BASE_DIR = Path(__file__).resolve().parent.parent

###安全密钥
SECRET_KEY = 'django-insecure-l@q)k-kf8i66f=$5k3nu&0h$vl-*^xc9k!s=-ygjd^egc=+oi+'

###调试模式
DEBUG = True

###允许访问本项目的域名
ALLOWED_HOSTS = ['*']

###本项目中安装的所有应用
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ###注册子应用
    'goods',
    'test',
    'web',
    'user',
    'database',
    'database2',
    'database3',
    ###注册corsheaders应用(解决跨越访问问题)
    'corsheaders'
]

###本项目中安装的所有中间件
MIDDLEWARE = [
    ###注册corsheaders.middleware.CorsMiddleware中间件(解决跨越访问问题)
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

###路由
ROOT_URLCONF = 'demo.urls'

###模板配置
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        ###指定模板路径
        'DIRS': [BASE_DIR/"templates"],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

###WSGI应用程序对象的位置
WSGI_APPLICATION = 'demo.wsgi.application'

###数据库配置
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django',
        'HOST': 'localhost',
        'PORT': 3306,
        'USER': 'root',
        'PASSWORD': '1989',
        'POOL_OPTIONS':{
            'POOL_SIZE':10,
            'MAX_OVERFLOW':30
        }
    }
}

###密码验证器
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

###国际化和本地化配置
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True

###静态资源路径
STATIC_URL = '/static/'

###模型自动生成的主键字段类型
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

###配置CORS允许的来源
#允许所有源访问
CORS_ALLOW_ALL_ORIGINS = True
#指定允许访问的源
"""
CORS_ALLOWED_ORIGINS = [
    "http://localhost:63342",
    "http://127.0.0.1:8000",
]
"""